package edu.nf.api.controller.user;

import edu.nf.api.controller.BaseController;
import edu.nf.util.sms.SMSUtil;
import edu.nf.waimai.service.user.impl.UserServiceImpl;
import org.nf.web.annotation.RequestMapping;
import org.nf.web.annotation.RequestParam;
import org.nf.web.servlet.View;
import org.nf.web.servlet.view.JsonView;

/**
 * @Date 2023-06-20
 * @Author qiu
 * 用户注册控制器
 */
public class RegisterController extends BaseController {

    @RequestMapping("/send")
    public View sendKey(@RequestParam("Phone") String riderPhone) {
        String send = new SMSUtil().send(riderPhone);
        // 保存到会话作用域中
        return new JsonView(success(send));
    }

    /**
     * @param userName 用户名
     * @param pwd      密码
     * @param nickName 匿名
     * @param phone    手机号
     * @return
     */
    @RequestMapping("/register")
    public View registerUser(@RequestParam("userName") String userName, @RequestParam("pwd") String pwd,
                             @RequestParam("nickName") String nickName, @RequestParam("phone") String phone) {

        int row = new UserServiceImpl().registerUser(userName, pwd, nickName, phone);

        return new JsonView(success());
    }

}
